/**
 * project: finance-manage
 * package: com.example.models
 * 读取配置文件
 */

package com.example.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Scanner;

import com.example.models.JsonModel;

public class ReadConfig {

    public Properties getDatabaseConfig() throws IOException {
        Properties properties = new Properties();
        InputStream input = getClass().getClassLoader().getResourceAsStream("database_config.properties");
        properties.load(input);

        return properties;
    }

    public JsonModel getErrCodeDictJson() throws IOException {
        /* 读取resources下的errno_code_dict.json文件内容并加载到JsonModel对象后返回 */
        InputStream input =  getClass().getClassLoader().getResourceAsStream("error_code_dict.json");
        Scanner scanner = new Scanner(input);
        String jsonStr = "";
        while (scanner.hasNextLine()) {
            jsonStr += scanner.nextLine();
        }
        scanner.close();
        return new JsonModel(jsonStr);

    }
}
